package com.xiaoyy.app.extend.gateway.config.aspect;


import com.xiaoyy.app.extend.gateway.config.ErrorUtil;
import com.xiaoyy.core.common.vo.AppResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 *
 * 统一处理异常信息
 */
@ControllerAdvice
public class ErrorController {
    protected Logger logger = LoggerFactory.getLogger(this.getClass());

    @ExceptionHandler
    @ResponseBody
    public AppResponse handleAndReturnData(HttpServletRequest request, HttpServletResponse response, Exception ex) {
        logger.error("统一异常处理:",ex);
        return ErrorUtil.errorResponse(ex);
    }

}
